<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="btn1">发起请求</button>
    <button class="btn2">请求失败</button>
    <h1></h1>
    <!-- <script src="./03.Promise基本用法.js"></script> -->
    <script src="./Promise封装请求方式.js"></script>

    <!-- <script>
        const btn = document.querySelector('button')
        btn.addEventListener('click', async function () {
            const res = await harryAjax({ method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' })
            console.log(res);
        })
    </script> -->
    <script>
        // document.querySelector('button').addEventListener('click', async function () {
        //     const res = await myAjxa({ method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' })
        //     const { data } = res
        //     console.log(data);
        // })
        const btn1=document.querySelector('.btn1')
        const btn2=document.querySelector('.btn2')
        const h1 = document.querySelector('h1')
        const abc=('欢迎来到主页')
        const  obj= {
            method: 'get',
            url: 'http://www.liulongbin.top:3006/api/getbooks'
        }
       const oej={
            method: 'POST',
            url: 'http://www.liulongbin.top:3006/api/addbook',
            data: { bookname: '前端开发实战', author: '老师们', publisher: '黑马程序员' }
        }
        btn1.addEventListener('click',  function () {
            Promise.all([myAjxa(obj)],[myAjxa(oej)]).then(res=>{
                console.log(res);
                h1.innerHTML=(abc)
            }).catch(err=>{
                console.log(err);
              
            });
        })
        btn2.addEventListener('click',  function () {
            Promise.race([myAjxa(obj+1)],[myAjxa(oej)]).then(res=>{
                console.log(res);
            }).catch(err=>{
                console.log(err);
                h1.innerHTML=(err)
                
            });
        })

     
        
    </script>
</body>

</html>